<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class bagian_jenis_aktifitas_model extends CI_Model {

    function __construct() 
	{
        parent::__construct();
        $this->CI = get_instance();
    }
	
	function selectone($id_bagian_jenis_aktifitas) 
	{
		$this->db->select("*");
        $this->db->from('bagian_jenis_aktifitas');
		$this->db->join('jenis_aktifitas AS JA','bagian_jenis_aktifitas.id_jenis_aktifitas = JA.id_jenis_aktifitas','left');
		$this->db->where('id_bagian_jenis_aktifitas', $id_bagian_jenis_aktifitas);        
        $query = $this->db->get();
        return $query;
	}
	
	function selectone2($id_satuan_jenis_aktifitas) 
	{
		$this->db->select("*");
        $this->db->from('satuan_jenis_aktifitas');
		$this->db->join('bagian_jenis_aktifitas AS BJA','satuan_jenis_aktifitas.id_bagian_jenis_aktifitas = BJA.id_bagian_jenis_aktifitas','left');
		$this->db->where('id_satuan_jenis_aktifitas', $id_satuan_jenis_aktifitas);        
        $query = $this->db->get();
        return $query;
	}
			
	function get_nama_satuan_aktifitas($id_bagian_jenis_aktifitas) 
	{
        //Build contents query
		$this->db->select('s.*, ks.*');
		$this->db->from('satuan_jenis_aktifitas ks');
		$this->db->join('bagian_jenis_aktifitas as s', 'ks.id_bagian_jenis_aktifitas = s.id_bagian_jenis_aktifitas', 'left');
		// $this->db->join('aktifitas as a', 'ks.id_satuan_jenis_aktifitas = a.id_satuan_jenis_aktifitas', 'left');
		$this->db->where('ks.id_bagian_jenis_aktifitas', $id_bagian_jenis_aktifitas);
		// $this->db->where('a.id_satuan_jenis_aktifitas', $id_satuan_jenis_aktifitas);
		$this->CI->flexigrid->build_query();		
		
        //Get contents
        $return['records'] = $this->db->get();

        //Build count query
        $this->db->select('s.*, ks.*');
		$this->db->from('satuan_jenis_aktifitas ks');
		$this->db->join('bagian_jenis_aktifitas as s', 'ks.id_bagian_jenis_aktifitas = s.id_bagian_jenis_aktifitas', 'left');
		// $this->db->join('aktifitas as a', 'ks.id_satuan_jenis_aktifitas = a.id_satuan_jenis_aktifitas', 'left');
		$this->db->where('ks.id_bagian_jenis_aktifitas', $id_bagian_jenis_aktifitas);
		// $this->db->where('a.id_satuan_jenis_aktifitas', $id_satuan_jenis_aktifitas);
		$this->CI->flexigrid->build_query(FALSE);

        $return['record_count'] = $this->db->count_all_results();

        //Return all
        return $return;
    }
	
	function get_cb($id_bagian_jenis_aktifitas){
			$query = $this->db->query("SELECT * 
				FROM satuan_jenis_aktifitas P LEFT JOIN bagian_jenis_aktifitas PO ON P.id_bagian_jenis_aktifitas = PO.id_bagian_jenis_aktifitas				
				WHERE P.id_bagian_jenis_aktifitas = '".$id_bagian_jenis_aktifitas."' ");					
			return $query;		  
		}	
		
	function sum_mesin_prod($id_perusahaan){
			$query = $this->db->query("SELECT SUM(HARGA_RUPIAH) as SUM_MESIN_PROD from DISPERDAGINDB.IUI_MESIN WHERE ID_M_PERUSAHAAN = ".$id_perusahaan." AND TIPE_MESIN = 1 GROUP BY ID_M_PERUSAHAAN");
			return $query; 
		}
		
	function get_data_bagian_jenis_aktifitas_ja()
	{
		//Select table name
		$table_name = "bagian_jenis_aktifitas";
		
		//Build contents query
		$this->db->select('*')->from($table_name);
		$this->db->join('jenis_aktifitas AS H','bagian_jenis_aktifitas.id_jenis_aktifitas = H.id_jenis_aktifitas','left');
		$this->CI->flexigrid->build_query();
		
		//Get contents
		$return['records'] = $this->db->get();
		
		//Build count query
		$this->db->select('*')->from($table_name);
		$this->db->join('jenis_aktifitas AS H','bagian_jenis_aktifitas.id_jenis_aktifitas = H.id_jenis_aktifitas','left');
		$this->CI->flexigrid->build_query(FALSE);
		
		$return['record_count'] = $this->db->count_all_results();
	
		//Return all
		return $return;
	}	
	
	function get_nama_satuan_bagian_aktifitas() 
	{
		//Select table name
		$table_name = "satuan_jenis_aktifitas";
		
		//Build contents query
		$this->db->select('*')->from($table_name);
		$this->db->join('bagian_jenis_aktifitas AS P','satuan_jenis_aktifitas.id_bagian_jenis_aktifitas = P.id_bagian_jenis_aktifitas','left');
		$this->CI->flexigrid->build_query();
		
		//Get contents
		$return['records'] = $this->db->get();
		
		//Build count query
		$this->db->select('*')->from($table_name);
		$this->db->join('bagian_jenis_aktifitas AS P','satuan_jenis_aktifitas.id_bagian_jenis_aktifitas = P.id_bagian_jenis_aktifitas','left');
		$this->CI->flexigrid->build_query(FALSE);
		
		$return['record_count'] = $this->db->count_all_results();
	
		//Return all
		return $return;	
	}
	
	function data_form_nilai($id_bagian_jenis_aktifitas, $id_satuan_jenis_aktifitas, $ID_EVALUASI)
	{
		$this->db->select('s.*, ks.*');
		$this->db->from('aktifitas_progress ks');
		$this->db->join('satuan_jenis_aktifitas as s', 'ks.satuan_jenis_aktifitas = s.satuan_jenis_aktifitas', 'left');
		$this->db->where('ks.id_bagian_jenis_aktifitas', $id_bagian_jenis_aktifitas);
		$this->db->where('ks.id_satuan_jenis_aktifitas', $id_satuan_jenis_aktifitas);
		$this->db->where('ks.ID_EVALUASI', $ID_EVALUASI);
		// $this->db->order_by('s.nama_proses_aktifitas', 'asc');
		$query = $this->db->get();
        return $query;
	}
	
	function nilai_total_progress($id_satuan_jenis_aktifitas)
	{			
		$cek_tp = $this->db->query("SELECT SUM(persentase_volume)/COUNT(id_proses_aktifitas) AS TP1 FROM aktifitas where id_satuan_jenis_aktifitas = ".$id_satuan_jenis_aktifitas." and ID_EVALUASI = ".$this->session->userdata('ID_EVALUASI')."");
		return $cek_tp; 
	}	
	
	
	
}

?>